<!DOCTYPE HTML>
<html class="x-admin-sm" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>设置新密码 -后台管理员</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" th:href="@{/asserts/css/adminlogin.css}">
    <link href="https://css.mafengwo.net/css/cv/css+login+login_v2:mobile+css+omc+login-omc+login-omc^ZlY^1550829726.css" rel="stylesheet" type="text/css"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet" />
 	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
    <script th:src="@{/asserts/lib/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/asserts/js/xadmin.js}"  type="text/javascript" ></script>
 	
</head>
<body class="editPassword-bg">
    <div class="wrapper">
        <div class="container">
            <div class="signup-forms">
                <div class="signup-box">
                    <div class="add-info">
                        <div class="hd">设置新密码</div>
                            <div class="alert alert-info">安全提示:密码长度为8-16位。
                            </div>
							<form method="post" class="layui-form" >
                            <div class="form-field">
                                <input id="oldPassword" name="oldPassword" type="password" lay-verify="pass" placeholder="原来的密码" autocomplete="off"
                                        class="" />
                                
                            </div>
                            <div class="form-field">
                                <input id="newPassword" name="newPassword" type="password" lay-verify="pass" placeholder="新的密码" autocomplete="off"
                                        class="" />
                                
                            </div>
                            <div class="form-field">
                                <input id="rnewPassword" name="rnewPassword" type="password" lay-verify="repass" placeholder="确认密码" autocomplete="off"
                                        class="">
                                
                            </div>
                            <div class="submit-btn">
                                <button type="submit" lay-submit lay-filter="update">完成</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
    $(function  () {
    	toastr.options = 
		{
	        positionClass: "toast-top-center",
	        closeButton: true,
	        timeOut:"1000",
	    };
        layui.use('form', function(){
          var form = layui.form;
          
          //检测是否符合规范
          form.verify({
              pass: [/(.+){8,16}$/, '密码必须8到16位'],
              repass: function(value) {
                  if ($('#newPassword').val() != $('#rnewPassword').val()) {
                      return '两次密码不一致';
                  }
              }
          });
          
        //监听提交
          form.on('submit(update)', function(data){
        	  $.ajax({
					type:"post",
					url: "/admin/editPassword",
					data: JSON.stringify({oldPassword:$("#oldPassword").val(),newPassword:$("#newPassword").val()}),
				    contentType: "application/json",
				    dataType: "json",
				    async: true,
				    success: function (data) {
				    	if(data)
				    	{
				    		toastr.success('修改成功!1s后跳转');
				    		setTimeout(function () {
				        		xadmin.close();
			    	        	xadmin.father_reload();}, 1000);
				    	}
				    	else
				    	{
				    		toastr.warning('网络故障:修改失败！');
				    	}
				    	
				    },
				    error: function (e) {
				    	toastr.error('网络错误！')
				    }	
				});  
        	  return false;
            });
          
          
    });
    })
    
    
    
    </script>
</body>
</html>
